package com.ny.demo605;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Test {
        private final static String URL = "jdbc:mysql://localhost:3306/usersdb";
        private final static String ROOT = "root";
        private final static String PASSWORD = "123456";

    public static void main(String[] args) throws SQLException {
        Connection connection = DriverManager.getConnection(URL, ROOT, PASSWORD);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String name = scanner.next();
        System.out.println("请输入密码");
        String pwd = scanner.next();
        String sql = "insert into users(username,password) values(?,?);";
        PreparedStatement preparedStatement = ((Connection) connection).prepareStatement(sql); // 预编译
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, pwd);
        int i = preparedStatement.executeUpdate();
        if (i > 0) {
            System.out.println("注册成功");
        }
    }
}

